
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登陆</title>
    <script src="${pageContext.request.contextPath}/js/jquery-3.6.0.min.js"></script>
    <script>
        function login() {
            let username = $("#userName").val();
            let password = $("#password").val();
            $.ajax({
                type:'post',
                url:'${pageContext.request.contextPath}/userController/login',
                contentType:'application/json;charset=UTF-8',
                async: true,
                data: JSON.stringify({"username": username, "password": password}),
                success:function(data){
                     if(data.code === 500){
                         var obj = document.getElementById("tishi");
                         obj.innerHTML = "用户名或密码错误";
                    }
                    else{
                         window.location.href ="${pageContext.request.contextPath}/userController/show";
                    }
                }
            });
        }
    </script>
</head>
<body>
    <form action="" method="post">
        <table>
            <tr>
                <td><label for="userName">用户名:</label></td>
                <td><input type="text" id="userName" name="username"></td>
            </tr>
            <tr>
                <td><label for="password">密码:</label></td>
                <td><input type="password" id="password" name="password"></td>
                <td style="color: red" id="tishi"></td>
            </tr>

            <tr>
                <td></td>
                <td style="text-decoration: none;">
                    <input type="button" value="登录" onclick="login()">
                </td>
            </tr>
        </table>
    </form>
</body>
</html>
